﻿#include "lvgl_radio.h"
#include "lvgl_radio_anim.h"

__lvgl_radio_data lvgl_radio_data = {
    .cont_main = NULL,
    .task = NULL,
    .close_task = NULL,
    .ctrl_close_flag = false,
    .close_count = 0,
    .close_num = 0,
    .cont_select = NULL,
    .select_num = 0,
    .select_flag = false,
    .select_count = 0,
    .onoff = 0,
    .search_flag = false,
    .on_flag = false,
    .backstage_flag = true,
};




__lvgl_coord lvgl_radio_p_coord_buf[5] = {
    {0,126,60,45},
    {65,126,60,45},
    {129,126,60,45},
    {194,126,60,45},
    {259,126,60,45},
};
__lvgl_coord lvgl_radio_select_coord_buf[] = {
    {55,24,210,70},
    {31,90,260,29},
    {2,122,315,47},
    {1,13,25,106},
    {294,13,25,106},
    {23,27,35,32},
    {23,57,35,32},
    {-10,-10,0,0},


};

static void lvgl_radio_set_show_ctrl(bool sta);


void lvgl_radio_task_cb(lv_task_t* t)
{
    static uint16_t cnt2 = 0;
    if (lvgl_radio_data.ctrl_close_flag == true)
    {

        if(lvgl_radio_data.save_flag == 1)
        {
            lvgl_radio_data.select_count = 0;
        }

        if (++lvgl_radio_data.select_count > 10 * 5)
        {
            lvgl_radio_data.select_count = 0;
            lvgl_radio_data.ctrl_close_flag = false;
            lvgl_radio_set_show_ctrl(lvgl_radio_data.ctrl_close_flag);

        }

    }

    if (lvgl_radio_data.search_flag == true)
    {
        lvgl_radio_data.select_count = 0;
        if (system_get_radio_search_status() == true)
        {
            lvgl_radio_data.search_flag = false;
            lvgl_radio_data.frequency = system_get_radio_frequency();
            lvgl_radio_anim_frequency_start(lvgl_radio_data.frequency_old, lvgl_radio_data.frequency);
            lvgl_radio_data.frequency_old = lvgl_radio_data.frequency;


        }
    }
#if USE_WIN
    if (lvgl_radio_data.search_flag == true)
    {
        if (++cnt2 >= 10 * 0.5)
        {
            cnt2 = 0;
            system_set_radio_search_status(true);
        }
    }

#endif

    if (lvgl_radio_data.on_flag == true)
    {
        lvgl_radio_debug("open radio");
        lvgl_radio_data.on_flag = false;

        lvgl_radio_data.onoff = 1;
        //system_set_radio_onoff(lvgl_radio_data.onoff);
        system_set_radio_mute(0);
        //system_set_radio_vol(lvgl_radio_data.vol * 0.15);
        //system_set_radio_sig(lvgl_radio_data.set_sig * 0.15);
        system_set_radio_frequency(lvgl_radio_data.frequency);
        system_set_spk_switch(SPK_SWITCH_ON);
        system_audio_select(AUDIO_SELECT_RADIO);


        lvgl_radio_data.search_flag = true;
        system_set_radio_next_search();
        lv_label_set_text(lvgl_radio_data.label_frequency, lvgl_globa_text[23][system_get_Language()]);
        lv_obj_align(lvgl_radio_data.label_frequency, NULL, LV_ALIGN_IN_TOP_MID, 0, 28);

        lvgl_radio_data.ctrl_close_flag = true;
        lvgl_radio_set_show_ctrl(lvgl_radio_data.ctrl_close_flag);
    }

}

void lvgl_radio_close_task_cb(lv_task_t* t)
{
    static uint8_t cnt = 0;

    if (lvgl_radio_data.ctrl_close_flag == true)
    {
        if (++cnt >= lvgl_radio_data.close_count)
        {
            cnt = 0;
            lvgl_radio_data.ctrl_close_flag = false;
            lvgl_task_delete(&lvgl_radio_data.close_task);

            if (lvgl_radio_data.close_num == 0)
            {

                if (lvgl_radio_data.backstage_flag == false)
                {
                    lvgl_radio_data.onoff = 0;
                }
                else if (lvgl_radio_data.backstage_flag == true)
                {
                    if(lvgl_radio_data.on_flag == true)//如果已经打开收音机
                    {
                        lvgl_radio_data.onoff = 1;
                    }

                }

                if (lvgl_radio_data.onoff == 0)
                {

                    system_set_spk_switch(SPK_SWITCH_OFF);
                    system_set_radio_onoff(0);
                    system_set_radio_mute(1);

                }
                lvgl_radio_data.ctrl_close_flag = false;
                lvgl_radio_set_show_ctrl(lvgl_radio_data.ctrl_close_flag);
                lvgl_radio_anim_out_start(0, 0);
            }


        }
    }
}

void lvgl_radio_set_backstage_sta(uint8_t sta,bool show_hint)
{
    if(sta== 0)
    {
        lv_img_set_src(lvgl_radio_data.image_background, &img_radio_0009);
        if(show_hint==true)
            lvgl_hint_create(lv_scr_act(),lvgl_globa_text[33][system_get_Language()],200,3);

    }else
    if(sta == 1)
    {

        lv_img_set_src(lvgl_radio_data.image_background, &img_radio_0008);
        if(show_hint==true)
        lvgl_hint_create(lv_scr_act(),lvgl_globa_text[32][system_get_Language()],200,3);

    }


}

void lvgl_radio_ctrl_select(uint8_t num)
{
    lvgl_radio_debug("ctrl select:%d", num);


    lvgl_radio_anim_select_x_start(lvgl_radio_select_coord_buf[num].x);
    lvgl_radio_anim_select_y_start(lvgl_radio_select_coord_buf[num].y);
    lvgl_radio_anim_select_w_start(lvgl_radio_select_coord_buf[num].w);
    lvgl_radio_anim_select_h_start(lvgl_radio_select_coord_buf[num].h);
}



void lvgl_radio_p_select(uint8_t num)
{
    lvgl_radio_debug("p select:%d", num);

    if(num == 0xff)
    {

        lvgl_radio_anim_p_pos_start(-50);
        return;
    }


    // if (lvgl_radio_data.anim_p_pos)
    // {
    //     lv_anim_del(lvgl_radio_data.anim_p_pos, NULL);
    //     lvgl_radio_anim_select_x_ready_cb(NULL);
    // }

    lvgl_set_obj_show(&lvgl_radio_data.cont_p);

    lvgl_set_obj_show(&lvgl_radio_data.p[0].image);
    lvgl_set_obj_show(&lvgl_radio_data.p[1].image);
    lvgl_set_obj_show(&lvgl_radio_data.p[2].image);
    lvgl_set_obj_show(&lvgl_radio_data.p[3].image);
    lvgl_set_obj_show(&lvgl_radio_data.p[4].image);
    lvgl_set_obj_hide(&lvgl_radio_data.p[num].image);

    lvgl_radio_anim_p_pos_start(lv_obj_get_x(lvgl_radio_data.p[num].cont)+lv_obj_get_x(lvgl_radio_data.p[num].image));

}

static void lvgl_radio_set_show_ctrl(bool sta)
{
    if(sta == true)
    {
        lv_obj_set_hidden(lvgl_radio_data.cont_select, false);
        lvgl_radio_ctrl_select(lvgl_radio_data.select_num);
        lvgl_radio_anim_vol_start(lv_obj_get_x(lvgl_radio_data.cont_vol), lvgl_radio_data.vol_align_x);
        lvgl_radio_anim_sig_start(lv_obj_get_x(lvgl_radio_data.cont_sig), lvgl_radio_data.sig_align_x);
        lvgl_radio_anim_background_start(lv_obj_get_y(lvgl_radio_data.image_background),30);
        lvgl_radio_anim_save_start(lv_obj_get_y(lvgl_radio_data.image_save),60);
    }else if(sta == false)
    {

        lvgl_radio_ctrl_select(7);
        lvgl_radio_anim_vol_start(lv_obj_get_x(lvgl_radio_data.cont_vol), -(lv_obj_get_width(lvgl_radio_data.cont_vol)));
        lvgl_radio_anim_sig_start(lv_obj_get_x(lvgl_radio_data.cont_sig), lv_obj_get_width(lvgl_radio_data.cont_main));
        lvgl_radio_anim_background_start(lv_obj_get_y(lvgl_radio_data.image_background),-(lv_obj_get_height(lvgl_radio_data.image_background)));
        lvgl_radio_anim_save_start(lv_obj_get_y(lvgl_radio_data.image_save),-(lv_obj_get_height(lvgl_radio_data.image_save)));
        lv_obj_set_hidden(lvgl_radio_data.cont_select,true);

    }
}
void lvgl_radio_detect_p(char *data)
{
    int i=0;

    if(lvgl_radio_data.save_flag == 1)
    {
        return;
    }

    for(i = 0;i<5;i++)
    {
        if(strstr(data,system_get_radio_p(i)))
        {
            lvgl_radio_data.p_num = i;
            lvgl_radio_p_select(lvgl_radio_data.p_num);
            break;
        }
    }
    if(i>=5)
    {
        lvgl_radio_data.p_num=0xff;
        lvgl_radio_p_select(lvgl_radio_data.p_num);
    }


}

void lvgl_radio_event_cb(struct _lv_obj_t* obj, lv_event_t event)
{

    if (obj == lvgl_radio_data.cont_main)
    {

        //lvgl_radio_debug("cb:%d", event);
        switch (event)
        {
        case LV_EVENT_KEY:

            switch (*(const uint32_t*)lv_event_get_data())
            {
            case LV_KEY_UP:
                lvgl_radio_debug("LV_KEY_UP");

                break;
            case LV_KEY_DOWN:
                lvgl_radio_debug("LV_KEY_DOWN");

                break;
            case LV_KEY_LEFT:
                lvgl_radio_debug("LV_KEY_LEFT");

                lvgl_radio_data.select_count = 0;

                if (lvgl_radio_data.onoff == 0)
                {
                    lvgl_radio_open();
                    break;
                }


                if (lvgl_radio_data.ctrl_close_flag == false)
                {
                    lvgl_radio_data.ctrl_close_flag = true;
                    lvgl_radio_set_show_ctrl(lvgl_radio_data.ctrl_close_flag);

                    break;
                }

                if(lvgl_radio_data.p_save_flag == true)
                {


                    break;
                }


                if (lvgl_radio_data.select_num == 0)
                {

                    if (lvgl_radio_data.search_flag == true)
                    {
                        break;
                    }
                    lvgl_radio_data.search_flag = true;
                    system_set_radio_last_search();
                    lv_label_set_text(lvgl_radio_data.label_frequency, lvgl_globa_text[23][system_get_Language()]);
                    lv_obj_align(lvgl_radio_data.label_frequency, NULL, LV_ALIGN_IN_TOP_MID, 0, 28);


                }
                else
                if (lvgl_radio_data.select_num == 1)
                {
                    lvgl_radio_data.frequency -= 10;
                    if (lvgl_radio_data.frequency <= 8700)
                    {

                        lvgl_radio_data.frequency = 10800;
                    }
                    system_set_radio_frequency(lvgl_radio_data.frequency);
                    lvgl_radio_anim_frequency_start(lvgl_radio_data.frequency_old, lvgl_radio_data.frequency);
                    lvgl_radio_data.frequency_old = lvgl_radio_data.frequency;
                }
                else
                if (lvgl_radio_data.select_num == 2)
                {

                    lvgl_radio_data.p_num -= 1;
                    if (lvgl_radio_data.p_num <= -1)
                    {

                        lvgl_radio_data.p_num = 4;
                    }
                    lvgl_radio_p_select(lvgl_radio_data.p_num);

                    if(lvgl_radio_data.save_flag == 1)
                    {
                        break;
                    }


                    float fp = atof(system_get_radio_p(lvgl_radio_data.p_num));
                    int ip = fp*100;

                    lvgl_radio_debug("get radio fp:%0.1f ip:%d",fp,ip);
                    lvgl_radio_data.frequency = ip;
                    system_set_radio_frequency(lvgl_radio_data.frequency);
                    lvgl_radio_anim_frequency_start(lvgl_radio_data.frequency_old, lvgl_radio_data.frequency);
                    lvgl_radio_data.frequency_old = lvgl_radio_data.frequency;

                }
                else
                if (lvgl_radio_data.select_num == 3)
                {
                    lvgl_radio_data.vol -= 10;
                    if (lvgl_radio_data.vol <= 0)
                    {
                        lvgl_radio_data.vol = 0;

                    }

                    system_set_radio_vol(lvgl_radio_data.vol * 0.15);
                    lv_bar_set_value(lvgl_radio_data.bar_vol, lvgl_radio_data.vol, LV_ANIM_ON);
                    lvgl_radio_debug("set vol:%d", lvgl_radio_data.vol);
                }
                else
                if (lvgl_radio_data.select_num == 4)
                {
                    lvgl_radio_data.set_sig -= 10;
                    if (lvgl_radio_data.set_sig <= 0)
                    {
                        lvgl_radio_data.set_sig = 0;

                    }

                    system_set_radio_sig(lvgl_radio_data.set_sig * 0.15);
                    lv_bar_set_value(lvgl_radio_data.bar_sig, lvgl_radio_data.set_sig, LV_ANIM_ON);
                    lvgl_radio_debug("set sig:%d", lvgl_radio_data.set_sig);
                }
                else
                if (lvgl_radio_data.select_num == 5)
                {

                    if(lvgl_radio_data.backstage_flag == 1)
                    {
                        lvgl_radio_data.backstage_flag = 0;
                    }else
                    if(lvgl_radio_data.backstage_flag == 0)
                    {
                        lvgl_radio_data.backstage_flag = 1;
                    }
                    lvgl_radio_set_backstage_sta(lvgl_radio_data.backstage_flag,true);

                }
                else
                if (lvgl_radio_data.select_num == 6)
                {

                    if(lvgl_radio_data.save_flag == 1)
                    {
                        lvgl_radio_data.save_flag = 0;
                        lv_img_set_src(lvgl_radio_data.image_save, &img_radio_0007);
                        lvgl_hint_create(lv_scr_act(),lvgl_globa_text[35][system_get_Language()],200,3);

                    }else
                    if(lvgl_radio_data.save_flag == 0)
                    {

                        lvgl_radio_data.save_flag = 1;
                        lv_img_set_src(lvgl_radio_data.image_save, &img_radio_0006);
                        lvgl_hint_create(lv_scr_act(),lvgl_globa_text[34][system_get_Language()],200,3);

                        lvgl_radio_data.select_num = 2;
                        lvgl_radio_ctrl_select(lvgl_radio_data.select_num);
                        lvgl_radio_data.p_num = 0;
                        lvgl_radio_p_select(lvgl_radio_data.p_num);
                    }

                }
                break;
            case LV_KEY_RIGHT:
                lvgl_radio_debug("LV_KEY_RIGHT");
                lvgl_radio_data.select_count = 0;

                if (lvgl_radio_data.onoff == 0)
                {
                    lvgl_radio_open();
                    break;
                }


                if (lvgl_radio_data.ctrl_close_flag == false)
                {
                    lvgl_radio_data.ctrl_close_flag = true;

                    lvgl_radio_set_show_ctrl(lvgl_radio_data.ctrl_close_flag);
                    break;
                }



                if (lvgl_radio_data.select_num == 0)
                {

                    if (lvgl_radio_data.search_flag == true)
                    {
                        break;
                    }

                    lvgl_radio_data.search_flag = true;
                    system_set_radio_next_search();
                    lv_label_set_text(lvgl_radio_data.label_frequency, lvgl_globa_text[23][system_get_Language()]);
                    lv_obj_align(lvgl_radio_data.label_frequency, NULL, LV_ALIGN_IN_TOP_MID, 0, 28);

                }
                else
                    if (lvgl_radio_data.select_num == 1)
                    {
                        lvgl_radio_data.frequency += 10;
                        if (lvgl_radio_data.frequency > 10800)
                        {

                            lvgl_radio_data.frequency = 8700;
                        }
                        system_set_radio_frequency(lvgl_radio_data.frequency);
                        lvgl_radio_anim_frequency_start(lvgl_radio_data.frequency_old, lvgl_radio_data.frequency);
                        lvgl_radio_data.frequency_old = lvgl_radio_data.frequency;



                    }
                    else
                    if (lvgl_radio_data.select_num == 2)
                    {
                        lvgl_radio_data.p_num += 1;
                        if (lvgl_radio_data.p_num >= 5)
                        {

                            lvgl_radio_data.p_num = 0;
                        }
                        lvgl_radio_p_select(lvgl_radio_data.p_num);

                        if(lvgl_radio_data.save_flag == 1)
                        {
                            break;
                        }


                        float fp = atof(system_get_radio_p(lvgl_radio_data.p_num));
                        int ip = fp*100;

                        lvgl_radio_debug("get radio fp:%0.1f ip:%d",fp,ip);
                        lvgl_radio_data.frequency = ip;
                        system_set_radio_frequency(lvgl_radio_data.frequency);
                        lvgl_radio_anim_frequency_start(lvgl_radio_data.frequency_old, lvgl_radio_data.frequency);
                        lvgl_radio_data.frequency_old = lvgl_radio_data.frequency;


                    }
                    else
                        if (lvgl_radio_data.select_num == 3)
                        {
                            lvgl_radio_data.vol += 10;
                            if (lvgl_radio_data.vol >= 100)
                            {
                                lvgl_radio_data.vol = 100;

                            }

                            system_set_radio_vol(lvgl_radio_data.vol * 0.15);
                            lv_bar_set_value(lvgl_radio_data.bar_vol, lvgl_radio_data.vol, LV_ANIM_ON);
                            lvgl_radio_debug("set vol:%d", lvgl_radio_data.vol);
                        }
                        else
                        if (lvgl_radio_data.select_num == 4)
                        {
                            lvgl_radio_data.set_sig += 10;
                            if (lvgl_radio_data.set_sig >= 100)
                            {
                                lvgl_radio_data.set_sig = 100;

                            }

                            system_set_radio_sig(lvgl_radio_data.set_sig * 0.15);
                            lv_bar_set_value(lvgl_radio_data.bar_sig, lvgl_radio_data.set_sig, LV_ANIM_ON);
                            lvgl_radio_debug("set sig:%d", lvgl_radio_data.set_sig);
                        }
                        else
                if (lvgl_radio_data.select_num == 5)
                {

                    if(lvgl_radio_data.backstage_flag == 1)
                    {
                        lvgl_radio_data.backstage_flag = 0;
                    }else
                    if(lvgl_radio_data.backstage_flag == 0)
                    {
                        lvgl_radio_data.backstage_flag = 1;
                    }
                    lvgl_radio_set_backstage_sta(lvgl_radio_data.backstage_flag,true);

                }
                else
                if (lvgl_radio_data.select_num == 6)
                {

                    if(lvgl_radio_data.save_flag == 1)
                    {
                        lvgl_radio_data.save_flag = 0;
                        lv_img_set_src(lvgl_radio_data.image_save, &img_radio_0007);
                        lvgl_hint_create(lv_scr_act(),lvgl_globa_text[35][system_get_Language()],200,3);

                    }else
                    if(lvgl_radio_data.save_flag == 0)
                    {

                        lvgl_radio_data.save_flag = 1;
                        lv_img_set_src(lvgl_radio_data.image_save, &img_radio_0006);
                        lvgl_hint_create(lv_scr_act(),lvgl_globa_text[34][system_get_Language()],200,3);

                        lvgl_radio_data.select_num = 2;
                        lvgl_radio_ctrl_select(lvgl_radio_data.select_num);
                        lvgl_radio_data.p_num = 0;
                        lvgl_radio_p_select(lvgl_radio_data.p_num);

                    }

                }
                break;
            case LV_KEY_ESC:
                lvgl_radio_debug("LV_KEY_ESC");

                if (lvgl_radio_data.search_flag == true)
                {
                    lvgl_hint_create(lv_scr_act(), lvgl_globa_text[23][system_get_Language()], 200, 2);
                    break;
                }
                if (lvgl_radio_data.save_flag == true)
                {
                    lvgl_radio_data.save_flag = 0;
                    lv_img_set_src(lvgl_radio_data.image_save, &img_radio_0007);
                    lvgl_hint_create(lv_scr_act(),lvgl_globa_text[35][system_get_Language()],200,3);
                    lvgl_radio_detect_p(lv_label_get_text(lvgl_radio_data.label_frequency));

                    lvgl_radio_data.select_num = 6;
                    lvgl_radio_ctrl_select(lvgl_radio_data.select_num);

                    break;
                }

                lvgl_radio_data.ctrl_close_flag = true;
                lvgl_radio_data.close_count = 1;
                lvgl_radio_data.close_num = 0;
                lvgl_task_create(&lvgl_radio_data.close_task, lvgl_radio_close_task_cb, 10, LV_TASK_PRIO_HIGH, NULL);

                break;
            case LV_KEY_DEL:
                lvgl_radio_debug("LV_KEY_DEL");

                break;
            case LV_KEY_BACKSPACE:
                lvgl_radio_debug("LV_KEY_BACKSPACE");

                break;
            case LV_KEY_ENTER:
                lvgl_radio_debug("LV_KEY_ENTER");

                lvgl_radio_data.select_count = 0;

                if (lvgl_radio_data.onoff == 0)
                {
                    lvgl_radio_open();
                    break;
                }


                if(lvgl_radio_data.save_flag == 1)//在存台
                {
                    lvgl_radio_data.save_flag = 0;
                    lv_img_set_src(lvgl_radio_data.image_save, &img_radio_0007);
                    lvgl_hint_create(lv_scr_act(),lvgl_globa_text[35][system_get_Language()],200,3);

                    lvgl_radio_data.select_num = 0;
                    lvgl_radio_ctrl_select(lvgl_radio_data.select_num);


                    system_set_radio_p(lvgl_radio_data.p_num,lv_label_get_text(lvgl_radio_data.label_frequency));

                    system_save_config();

                    lv_label_set_text(lvgl_radio_data.p[lvgl_radio_data.p_num].label2, system_get_radio_p(lvgl_radio_data.p_num));
                    lv_obj_align(lvgl_radio_data.p[lvgl_radio_data.p_num].label2, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);


                    break;
                }

                if (lvgl_radio_data.ctrl_close_flag == false)
                {
                    lvgl_radio_data.ctrl_close_flag = true;
                    lvgl_radio_set_show_ctrl(lvgl_radio_data.ctrl_close_flag);

                    break;
                }


                if (++lvgl_radio_data.select_num >= 7)
                {

                    lvgl_radio_data.select_num = 0;
                }

                lvgl_radio_ctrl_select(lvgl_radio_data.select_num);


                break;
            case LV_KEY_NEXT:
                lvgl_radio_debug("LV_KEY_NEXT");

                break;
            case LV_KEY_PREV:
                lvgl_radio_debug("LV_KEY_PREV");

                break;
            case LV_KEY_HOME:
                lvgl_radio_debug("LV_KEY_HOME");

                break;
            case LV_KEY_END:
                lvgl_radio_debug("LV_KEY_END");

                break;


            }

            break;

        case CZ_EVENT_ENTER_LEFT:
            lvgl_radio_debug("enter left");




        break;
        case CZ_EVENT_ENTER_RIGHT:
            lvgl_radio_debug("enter right");



        break;
        case CZ_EVENT_ANIM_IN_READY:
            lvgl_radio_debug("event anim in ready");

            lvgl_radio_data.ctrl_close_flag = true;
            lvgl_radio_set_show_ctrl(lvgl_radio_data.ctrl_close_flag);
            lvgl_radio_detect_p(lv_label_get_text(lvgl_radio_data.label_frequency));

            break;
        case CZ_EVENT_ANIM_OUT_READY:
            lvgl_radio_debug("event anim out ready");



            break;

        case LV_EVENT_DELETE:

            lvgl_radio_data.cont_main = NULL;
            lvgl_radio_debug("delete win");
            break;

        case LV_EVENT_PRESSING://对象被持续按下

            break;
        case LV_EVENT_PRESSED://对象已被按下

            break;
        case LV_EVENT_DRAG_END://拖动结束后

            if (lv_obj_get_x(lvgl_radio_data.cont_main) != 0)
            {
                lv_obj_set_x(lvgl_radio_data.cont_main, 0);
            }

            if (lv_obj_get_y(lvgl_radio_data.cont_main) != 0)
            {
                lv_obj_set_y(lvgl_radio_data.cont_main, 0);
            }
            break;
        case LV_EVENT_RELEASED://按钮释放

        case LV_EVENT_LONG_PRESSED://按钮长按

            break;

        default:
            break;

        }
    }
}

void lvgl_radio_create(lv_obj_t* parent)
{

    lvgl_radio_data.select_flag = false;
    lvgl_radio_data.ctrl_close_flag = false;
    lvgl_radio_data.select_count = 0;
    lvgl_radio_data.select_num = 0;

    if (lvgl_radio_data.cont_main == NULL)
    {



        //----创建容器----//
        lvgl_radio_data.cont_main = lv_cont_create(parent, NULL);

        lv_obj_set_size(lvgl_radio_data.cont_main, lv_obj_get_width(parent), lv_obj_get_height(parent));
        lv_obj_set_pos(lvgl_radio_data.cont_main, 0, -(lv_obj_get_height(parent)));

        lv_obj_set_click(lvgl_radio_data.cont_main, true); //启用 / 禁用可点击
        lv_obj_set_drag(lvgl_radio_data.cont_main, true);//启用/禁用对象可拖动
        lv_obj_set_drag_throw(lvgl_radio_data.cont_main, true);//启用/禁用拖动后是否有惯性移动
        lv_obj_set_drag_parent(lvgl_radio_data.cont_main, false); //启用 / 禁用父对象可拖动
        lv_obj_set_drag_dir(lvgl_radio_data.cont_main, LV_DRAG_DIR_HOR);//设置拖动方向
        lv_obj_add_style(lvgl_radio_data.cont_main, LV_OBJ_PART_MAIN, &lvgl_style.cont_no_border);
        lv_obj_set_event_cb(lvgl_radio_data.cont_main, lvgl_radio_event_cb);
        //----创建容器----//


        //----后台播放----//
        lvgl_radio_data.image_background = lv_img_create(lvgl_radio_data.cont_main, NULL);
        lv_img_set_src(lvgl_radio_data.image_background, &img_radio_0008);
        lv_obj_set_pos(lvgl_radio_data.image_background, 27, -(lv_obj_get_height(lvgl_radio_data.image_background)));//30);
        //----后台播放----//

        //----存台----//
        lvgl_radio_data.image_save = lv_img_create(lvgl_radio_data.cont_main, NULL);
        lv_img_set_src(lvgl_radio_data.image_save, &img_radio_0007);
        lv_obj_set_pos(lvgl_radio_data.image_save, 27,-(lv_obj_get_height(lvgl_radio_data.image_save)));// 60);
        //----存台----//


        //----选择框----//
        lvgl_radio_data.cont_select = lv_cont_create(lvgl_radio_data.cont_main, NULL);
        lv_obj_set_size(lvgl_radio_data.cont_select, 0, 0);
        lv_obj_set_pos(lvgl_radio_data.cont_select, 0, 0);
        lv_obj_add_style(lvgl_radio_data.cont_select, LV_OBJ_PART_MAIN, &lvgl_style.cont_no_border);
        lv_obj_set_style_local_bg_color(lvgl_radio_data.cont_select, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
        lv_obj_set_style_local_bg_grad_color(lvgl_radio_data.cont_select, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
        lv_obj_set_style_local_bg_opa(lvgl_radio_data.cont_select, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 100);
        lv_obj_set_style_local_radius(lvgl_radio_data.cont_select, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 15);

        lv_obj_set_hidden(lvgl_radio_data.cont_select, false);
        lvgl_radio_data.select_flag = false;
        //----选择框----//


        //----刻度----//
        lvgl_radio_data.image1 = lv_img_create(lvgl_radio_data.cont_main, NULL);
        lv_obj_set_pos(lvgl_radio_data.image1, 0, 0);
        lv_img_set_src(lvgl_radio_data.image1, &img_radio_0003);
        lv_obj_align(lvgl_radio_data.image1, NULL, LV_ALIGN_IN_TOP_MID, 0, 98);
        //----刻度----//


        //----音量----//
        lvgl_radio_data.cont_vol = lv_cont_create(lvgl_radio_data.cont_main, NULL);
        lv_obj_set_size(lvgl_radio_data.cont_vol, 16, 100);
        lv_obj_set_pos(lvgl_radio_data.cont_vol, 0, 0);
        lv_obj_add_style(lvgl_radio_data.cont_vol, LV_OBJ_PART_MAIN, &lvgl_style.cont_transparent);
        lv_obj_align(lvgl_radio_data.cont_vol, NULL, LV_ALIGN_IN_TOP_LEFT, 5, 15);
        lvgl_radio_data.vol_align_x = lv_obj_get_x(lvgl_radio_data.cont_vol);
        lvgl_radio_data.vol_align_y = lv_obj_get_y(lvgl_radio_data.cont_vol);
        lv_obj_set_pos(lvgl_radio_data.cont_vol, -(lv_obj_get_width(lvgl_radio_data.cont_vol)), lvgl_radio_data.vol_align_y);



        lvgl_radio_data.image_vol = lv_img_create(lvgl_radio_data.cont_vol, NULL);
        lv_obj_set_pos(lvgl_radio_data.image_vol, 0, 0);
        lv_img_set_src(lvgl_radio_data.image_vol, &img_radio_0004);
        lv_obj_align(lvgl_radio_data.image_vol, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);


        lvgl_radio_data.vol = system_get_radio_vol() * 100/15;
        lvgl_radio_data.bar_vol = lv_bar_create(lvgl_radio_data.cont_vol, NULL);
        lv_obj_set_size(lvgl_radio_data.bar_vol, 8, 78);
        lv_obj_set_pos(lvgl_radio_data.bar_vol, 0, 0);
        //lv_obj_add_style(lvgl_radio_data.bar_vol, LV_OBJ_PART_MAIN, &lvgl_style.cont_transparent);
        lv_obj_align(lvgl_radio_data.bar_vol, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -(lv_obj_get_height(lvgl_radio_data.image_vol)) - 2);
        lv_bar_set_range(lvgl_radio_data.bar_vol, 0, 100);
        lv_bar_set_anim_time(lvgl_radio_data.bar_vol, 300);
        lv_bar_set_value(lvgl_radio_data.bar_vol, lvgl_radio_data.vol, LV_ANIM_ON);

        //----音量----//

        //----信号----//
        lvgl_radio_data.cont_sig = lv_cont_create(lvgl_radio_data.cont_main, NULL);
        lv_obj_set_size(lvgl_radio_data.cont_sig, 16, 100);
        lv_obj_set_pos(lvgl_radio_data.cont_sig, 0, 0);
        lv_obj_add_style(lvgl_radio_data.cont_sig, LV_OBJ_PART_MAIN, &lvgl_style.cont_transparent);
        lv_obj_align(lvgl_radio_data.cont_sig, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 15);
        lvgl_radio_data.sig_align_x = lv_obj_get_x(lvgl_radio_data.cont_sig);
        lvgl_radio_data.sig_align_y = lv_obj_get_y(lvgl_radio_data.cont_sig);
        lv_obj_set_pos(lvgl_radio_data.cont_sig, lv_obj_get_width(lvgl_radio_data.cont_main), lvgl_radio_data.sig_align_y);



        lvgl_radio_data.image_sig = lv_img_create(lvgl_radio_data.cont_sig, NULL);
        lv_obj_set_pos(lvgl_radio_data.image_sig, 0, 0);
        lv_img_set_src(lvgl_radio_data.image_sig, &img_radio_0005);
        lv_obj_align(lvgl_radio_data.image_sig, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);


        lvgl_radio_data.set_sig = system_get_radio_sig() * 100/15;
        lvgl_radio_data.bar_sig = lv_bar_create(lvgl_radio_data.cont_sig, NULL);
        lv_obj_set_size(lvgl_radio_data.bar_sig, 8, 78);
        lv_obj_set_pos(lvgl_radio_data.bar_sig, 0, 0);
        //lv_obj_add_style(lvgl_radio_data.bar_sig, LV_OBJ_PART_MAIN, &lvgl_style.cont_transparent);
        lv_obj_align(lvgl_radio_data.bar_sig, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -(lv_obj_get_height(lvgl_radio_data.image_sig)) - 2);
        lv_bar_set_range(lvgl_radio_data.bar_sig, 0, 100);
        lv_bar_set_anim_time(lvgl_radio_data.bar_sig, 300);
        lv_bar_set_value(lvgl_radio_data.bar_sig, lvgl_radio_data.set_sig, LV_ANIM_ON);
        //----信号----//

        //----频率----//

        lvgl_radio_data.label_frequency = lv_label_create(lvgl_radio_data.cont_main, NULL);
        lv_obj_set_pos(lvgl_radio_data.label_frequency, 90, 25);
        lv_label_set_long_mode(lvgl_radio_data.label_frequency, LV_LABEL_LONG_EXPAND);//循环滚动
        lv_obj_set_width(lvgl_radio_data.label_frequency, 0);
        lv_obj_set_height(lvgl_radio_data.label_frequency, 0);
        lv_label_set_recolor(lvgl_radio_data.label_frequency, true);
        lv_label_set_align(lvgl_radio_data.label_frequency, LV_LABEL_ALIGN_CENTER);
        lv_label_set_recolor(lvgl_radio_data.label_frequency, true);
        lv_label_set_text(lvgl_radio_data.label_frequency, "OFF");
        lv_obj_add_style(lvgl_radio_data.label_frequency, LV_OBJ_PART_MAIN, &lvgl_style.font48_white_bg);
        lv_obj_align(lvgl_radio_data.label_frequency, NULL, LV_ALIGN_IN_TOP_MID, 0, 28);

        if (lvgl_radio_data.onoff == 1)
        {
            lvgl_radio_data.frequency_old = 1000;
            lvgl_radio_data.frequency = system_get_radio_frequency();
            lvgl_radio_anim_frequency_start(lvgl_radio_data.frequency_old, lvgl_radio_data.frequency);
            lvgl_radio_data.frequency_old = lvgl_radio_data.frequency;
        }
        //----频率----//



        //----MHZ----//
        lvgl_radio_data.label_mhz = lv_label_create(lvgl_radio_data.cont_main, NULL);
        lv_obj_set_pos(lvgl_radio_data.label_mhz, 0, 0);
        lv_label_set_long_mode(lvgl_radio_data.label_mhz, LV_LABEL_LONG_EXPAND);//循环滚动
        lv_obj_set_pos(lvgl_radio_data.label_mhz, 0, 0);
        lv_obj_set_width(lvgl_radio_data.label_mhz, 240);
        lv_obj_set_height(lvgl_radio_data.label_mhz, 28);
        lv_label_set_recolor(lvgl_radio_data.label_mhz, true);
        lv_label_set_align(lvgl_radio_data.label_mhz, LV_LABEL_ALIGN_CENTER);
        lv_label_set_recolor(lvgl_radio_data.label_mhz, true);
        lv_label_set_text(lvgl_radio_data.label_mhz, "MHZ");
        lv_obj_add_style(lvgl_radio_data.label_mhz, LV_OBJ_PART_MAIN, &lvgl_style.font16_white_bg);
        lv_obj_align(lvgl_radio_data.label_mhz, NULL, LV_ALIGN_IN_TOP_RIGHT, -22, 70);
        lv_obj_set_style_local_text_color(lvgl_radio_data.label_mhz, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
        //----MHZ----//

        // lv_obj_set_hidden(lvgl_radio_data.label_mhz,true);
        // lv_obj_set_hidden(lvgl_radio_data.label_frequency, true);
        // lv_obj_set_hidden(lvgl_radio_data.image1, true);



        lvgl_radio_data.cont_p = lv_cont_create(lvgl_radio_data.cont_main, NULL);
        lv_obj_set_size(lvgl_radio_data.cont_p, 0,0);
        lv_obj_set_pos(lvgl_radio_data.cont_p,0,0);

        lv_obj_add_style(lvgl_radio_data.cont_p, LV_OBJ_PART_MAIN, &lvgl_style.cont_no_border);
        lv_obj_set_style_local_bg_color(lvgl_radio_data.cont_p, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,LV_COLOR_RED);
        lv_obj_set_style_local_bg_grad_color(lvgl_radio_data.cont_p, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,LV_COLOR_RED);
        lv_obj_set_style_local_bg_grad_color(lvgl_radio_data.cont_p, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,LV_COLOR_RED);
        lv_obj_set_style_local_radius(lvgl_radio_data.cont_p, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,5);

#if 1
        for (int i = 0; i < 5; i++)
        {
            lvgl_radio_data.p[i].cont = lv_cont_create(lvgl_radio_data.cont_main, NULL);
            lv_obj_set_size(lvgl_radio_data.p[i].cont, lvgl_radio_p_coord_buf[i].w, lvgl_radio_p_coord_buf[i].h);
            lv_obj_set_pos(lvgl_radio_data.p[i].cont, lvgl_radio_p_coord_buf[i].x, lvgl_radio_p_coord_buf[i].y);
            lv_obj_add_style(lvgl_radio_data.p[i].cont, LV_OBJ_PART_MAIN, &lvgl_style.cont_transparent);


            lvgl_radio_data.p[i].image = lv_img_create(lvgl_radio_data.p[i].cont, NULL);
            lv_obj_set_pos(lvgl_radio_data.p[i].image, 0, 0);

            lv_img_set_src(lvgl_radio_data.p[i].image, &img_radio_0002);
            lv_obj_align(lvgl_radio_data.p[i].image, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -3);

            lvgl_radio_data.p[i].label1 = lv_label_create(lvgl_radio_data.p[i].cont, NULL);
            lv_obj_set_pos(lvgl_radio_data.p[i].label1, 0, 0);
            lv_label_set_long_mode(lvgl_radio_data.p[i].label1, LV_LABEL_LONG_EXPAND);//循环滚动
            lv_obj_set_pos(lvgl_radio_data.p[i].label1, 0, 0);
            lv_obj_set_width(lvgl_radio_data.p[i].label1, 240);
            lv_obj_set_height(lvgl_radio_data.p[i].label1, 28);
            lv_label_set_recolor(lvgl_radio_data.p[i].label1, true);
            lv_label_set_align(lvgl_radio_data.p[i].label1, LV_LABEL_ALIGN_CENTER);
            lv_label_set_recolor(lvgl_radio_data.p[i].label1, true);
            sprintf(lvgl_radio_data.p_buf, "P%d", i+1);
            lv_label_set_text(lvgl_radio_data.p[i].label1, lvgl_radio_data.p_buf);
            lv_obj_add_style(lvgl_radio_data.p[i].label1, LV_OBJ_PART_MAIN, &lvgl_style.font16_white_bg);
            lv_obj_align(lvgl_radio_data.p[i].label1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -2);


            lvgl_radio_data.p[i].label2 = lv_label_create(lvgl_radio_data.p[i].cont, lvgl_radio_data.p[i].label1);
            lv_label_set_text(lvgl_radio_data.p[i].label2, system_get_radio_p(i));
            lv_obj_align(lvgl_radio_data.p[i].label2, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);

            lv_obj_move_foreground(lvgl_radio_data.p[i].label2);

        }
#endif


        lv_obj_set_size(lvgl_radio_data.cont_p, lv_obj_get_width(lvgl_radio_data.p[0].image), lv_obj_get_height(lvgl_radio_data.p[0].image));
        lv_obj_set_pos(
            lvgl_radio_data.cont_p,
            lv_obj_get_x(lvgl_radio_data.p[0].cont)+lv_obj_get_x(lvgl_radio_data.p[0].image),
            lv_obj_get_y(lvgl_radio_data.p[0].cont)+lv_obj_get_y(lvgl_radio_data.p[0].image)
        );
        lvgl_set_obj_hide(&lvgl_radio_data.cont_p);
        //lvgl_set_obj_hide(&lvgl_radio_data.p[0].image);

        lvgl_task_create(&lvgl_radio_data.task, lvgl_radio_task_cb, 100, LV_TASK_PRIO_HIGH, NULL);

        lvgl_radio_debug("create win");
    }
    else
    {
        lvgl_radio_debug("show win");
    }
    lv_obj_get_x(lvgl_radio_data.cont_main);
    if(lvgl_radio_data.backstage_flag == false)
    {
        lv_label_set_text(lvgl_radio_data.label_frequency, "OFF");
        lv_obj_align(lvgl_radio_data.label_frequency, NULL, LV_ALIGN_IN_TOP_MID, 0, 28);
    }
    lvgl_radio_set_backstage_sta(lvgl_radio_data.backstage_flag,false);

    lv_obj_move_background(lvgl_radio_data.cont_main);
    lvgl_set_obj_show(&lvgl_radio_data.cont_main);
    lvgl_radio_anim_in_start(0, 0);

}

void lvgl_radio_set_frequency(int data)
{
    char buf[20];
    float fre = (float)data;
    sprintf(buf, "%0.2f", fre / 100);

    lv_label_set_text(lvgl_radio_data.label_frequency, buf);
    lv_obj_align(lvgl_radio_data.label_frequency, NULL, LV_ALIGN_IN_TOP_MID, 0, 28);
}
void lvgl_radio_open(void)
{

    lvgl_radio_data.on_flag = true;


}

void lvgl_radio_hidden(void)
{

}

void lvgl_radio_close(void)
{
    lvgl_radio_debug("close");
    lvgl_group_remove_obj(&lvgl_radio_data.cont_main);

    lvgl_task_delete(&lvgl_radio_data.task);
    lvgl_obj_clean(&lvgl_radio_data.cont_main);
    lvgl_obj_del(&lvgl_radio_data.cont_main);

    //lvgl_set_obj_hide(&lvgl_radio_data.cont_main);


    lvgl_desktop_create(lv_scr_act());
}










